HAL RCC types migration

This section provides information about the HAL RCC types migration, followed by the HAL CRS types migration.

HAL RCC PLL initialization type definition

In HAL2, PLL state is removed from the configuration structure and PLL source is defined using enumeration hal_rcc_pll_src_t.

HAL1

HAL2

typedef struct
{
  uint32_t PLLState;
  uint32_t PLLSource;
  uint32_t PLLM;
  uint32_t PLLMBOOST;
  uint32_t PLLN;
  uint32_t PLLP;
  uint32_t PLLQ;
  uint32_t PLLR;
  uint32_t PLLRGE;
  uint32_t PLLFRACN;
} RCC_PLLInitTypeDef;
typedef struct
{
  uint16_t pll_n;
  uint16_t pll_fracn;
  uint8_t pll_m;
  uint8_t pll_p;
  uint8_t pll_q;
  uint8_t pll_r;
  hal_rcc_pll_mboost_div_t pll_m_boost;
  hal_rcc_pll_src_t pll_source;
} hal_rcc_pll_config_t;

Related concepts:


HAL RCC oscillator initialization type definition

In HAL2, the RCC_OscInitTypeDef structure has been removed in accordance with the concept of providing unitary APIs to configure the oscillator.

typedef struct
{
  uint32_t OscillatorType;
  uint32_t HSEState;
  uint32_t LSEState;
  uint32_t HSIState;
  uint32_t HSICalibrationValue;
  uint32_t LSIState;
  uint32_t LSIDiv;
  uint32_t MSIState;
  uint32_t MSICalibrationValue;
  uint32_t MSIClockRange;
  uint32_t MSIKClockRange;
  uint32_t HSI48State;
  uint32_t SHSIState;
  uint32_t MSIKState;
  RCC_PLLInitTypeDef PLL;
} RCC_OscInitTypeDef;

Removed: Replace HAL_RCC_OscConfig with unitary APIs for individual RCC oscillators

Related use cases: System Clock Configuration


HAL RCC clock initialization type definition

In HAL2, the RCC_ClkInitTypeDef structure has undergone a major change with the removal of the clock type and clock source selection, as well as modifications to the structure name and each type, such as the bus prescalers.

HAL1

HAL2

typedef struct
{
  uint32_t ClockType;
  uint32_t SYSCLKSource;
  uint32_t AHBCLKDivider;
  uint32_t APB1CLKDivider;
  uint32_t APB2CLKDivider;
  uint32_t APB3CLKDivider;
} RCC_ClkInitTypeDef;
/* unitary API are provided in HAL2 to cover this feature */

typedef struct
{
  hal_rcc_hclk_prescaler_t hclk_prescaler;
  hal_rcc_pclk_prescaler_t pclk1_prescaler;
  hal_rcc_pclk_prescaler_t pclk2_prescaler;
  hal_rcc_pclk_prescaler_t pclk3_prescaler;
} hal_rcc_bus_clk_config_t;

Related concepts:

Related use cases: Switch System Clock Source to HSI


HAL RCC PLL clocks type definition

In HAL1, the structures for configuring the output frequencies of PLL1, PLL2, and PLL3 were defined separately. In HAL2, these structures have been unified into a single structure for better consistency and ease of use. The configuration and retrieval of PLL output frequencies are now handled through unitary APIs.

HAL1

HAL2

typedef struct
{
  uint32_t PLL1_P_Frequency;
  uint32_t PLL1_Q_Frequency;
  uint32_t PLL1_R_Frequency;
} PLL1_ClocksTypeDef;

typedef struct
{
  uint32_t PLL2_P_Frequency;
  uint32_t PLL2_Q_Frequency;
  uint32_t PLL2_R_Frequency;
} PLL2_ClocksTypeDef;

typedef struct
{
  uint32_t PLL3_P_Frequency;
  uint32_t PLL3_Q_Frequency;
  uint32_t PLL3_R_Frequency;
} PLL3_ClocksTypeDef;
typedef struct
{
  uint32_t pll_p_freq; /*!< PLLx outputP frequency */
  uint32_t pll_q_freq; /*!< PLLx outputQ frequency */
  uint32_t pll_r_freq; /*!< PLLx outputR frequency */
} hal_rcc_pll_output_freq_t;

HAL RCC peripheral clock initialization type definition

In HAL2, the structure for configuring peripheral clocks has been removed. The configuration is now handled through unitary APIs.

typedef struct
{
  uint64_t PeriphClockSelection;
  RCC_PLL2InitTypeDef PLL2;
  RCC_PLL3InitTypeDef PLL3;
  uint32_t Usart1ClockSelection;
  #if defined(USART2)
  uint32_t Usart2ClockSelection;
  #endif /* USART2 */
  uint32_t Usart3ClockSelection;
  uint32_t Uart4ClockSelection;
  uint32_t Uart5ClockSelection;
  .....

} RCC_PeriphCLKInitTypeDef;

Removed Peripheral-specific APIs for clock source selection

Related use case: Set peripheral clock source


HAL RCC CRS Initialization type definition

HAL1

HAL2

In HAL1, automatic trimming is enabled implicitly when calling the function HAL_RCCEx_CRSConfig().

In HAL2, the configuration structure hal_crs_config_t allows explicit control over automatic trimming, enabling it to be turned on or off as needed.

typedef struct
{
  uint32_t Prescaler;
  uint32_t Source;
  uint32_t Polarity;
  uint32_t ReloadValue;
  uint32_t ErrorLimitValue;
  uint32_t HSI48CalibrationValue;
  /* The auto trimming is internally enabled in HAL_RCCEx_CRSConfig() */
} RCC_CRSInitTypeDef;
typedef struct
{
  hal_crs_sync_div_t divider;
  hal_crs_sync_source_t source;
  hal_crs_sync_polarity_t polarity;
  uint32_t reload;
  uint32_t frequency_error_limit;
  uint32_t trimming;
  hal_crs_auto_trimming_state_t auto_trimming;
} hal_crs_config_t;

Related concept:

Removal and conversion of init structure to configuration structure


HAL RCC CRS Synchronization type definition

HAL1

HAL2

typedef struct
{
  uint32_t FreqErrorCapture;
  uint32_t FreqErrorDirection;
  uint32_t ReloadValue;
  uint32_t HSI48CalibrationValue;
} RCC_CRSSynchroInfoTypeDef;
typedef struct
{
  uint32_t frequency_error_capture;
  hal_crs_frequency_error_dir_t frequency_error_dir;
  /* Removed: already defined in hal_crs_config_t */
  /* Removed: already defined in hal_crs_config_t */
} hal_crs_frequency_error_info_t;